﻿@model BE.ModelosIII.Mvc.Models.Scenario.ScenarioModel

@{
    ViewBag.Title = "Ver Escenario - " + Model.Name;
    Layout = ViewBag.Layout;
}

<section class="utopia-widget">
    <div class="utopia-widget-title">
        <img class="utopia-widget-icon" src="/Content/img/icons/paragraph_justify.png">
        <span>Ver Escenario</span>
    </div>
    <div class="utopia-widget-content">
        @Html.Partial("_ViewForm", Model)
    </div>
</section>


@section scripts {
    <script type="text/javascript" src="/Content/fancybox/jquery.fancybox.pack.js"></script>
    <script type="text/javascript">
        $(function () {
            var errorUrl = '@Url.Action("ErrorProcessing", "Home")';
            var waitUrl = '@Url.Action("PleaseWait", "Home")';
            var validateUrl = '@Url.Action("ValidateConfiguration", "Scenario")';

            var findSolution = function (solutionUrl) {
                $.fancybox({
                    type: 'ajax',
                    href: waitUrl,
                    dataType: 'html',
                    closeClick: false,
                    closeBtn: false,
                    helpers: {
                        overlay: {
                            closeClick: false
                        }
                    }
                });

                $.getJSON(solutionUrl, function (result) {
                    if (result.success) {
                        window.location = result.redirectUrl;
                    }
                    else {
                        $.fancybox({
                            type: 'ajax',
                            href: errorUrl,
                            dataType: 'html'
                        });
                    }
                });
            };

            $('.runSolution').click(function (ev) {
                ev.preventDefault();

                var solutionUrl = $(this).data('href');
                var configuration = {};
                configuration.ScenarioId = $("#ScenarioId").val();
                configuration.CrossoverProbability = $("#Configuration_CrossoverProbability").val();
                configuration.MutationProbability = $("#Configuration_MutationProbability").val();
                configuration.PopulationSize = $("#Configuration_PopulationSize").val();
                configuration.StopCriterion = $("#Configuration_StopCriterion").val();
                configuration.StopDepth = $("#Configuration_StopDepth").val();
                configuration.Report = $("#Configuration_Report").is(':checked');

                $.post(validateUrl, configuration, function (result) {
                    $("#configuration").html(result.html);
                    showErrorsStyled();

                    if (result.success) {
                        findSolution(solutionUrl);
                    }
                }, 'json');
            });
        });
    </script>
}
@section css {
    <link href="/Content/fancybox/jquery.fancybox.css" rel="stylesheet" type="text/css" />
}
